package com.weilian.ordering.manager;

import java.io.File;
import java.util.Date;

public class SdcardManager {
	private static boolean sdcardAvailable;
	private static boolean sdcardAvailabilityDetected;

	/**
	 * 
	 * @return SD is available ?
	 */
	public static synchronized boolean detectSDCardAvailability() {
		boolean result = false;
		try {
			Date now = new Date();
			long times = now.getTime();
			String fileName = "/sdcard/" + times + ".test";
			File file = new File(fileName);
			result = file.createNewFile();
			file.delete();
		} catch (Exception e) {
			// Can't create file, SD Card is not available
			e.printStackTrace();
		} finally {
			sdcardAvailabilityDetected = true;
			sdcardAvailable = result;
		}
		return result;
	}

	public static boolean isSDCardAvailable() {
		if (!sdcardAvailabilityDetected) {
			sdcardAvailable = detectSDCardAvailability();
			sdcardAvailabilityDetected = true;
		}
		return sdcardAvailable;
	}
}
